<?php

namespace common\models;

use Yii;
use common\models\Type;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "xa_article".
 *
 * @property integer $id
 * @property string $xa_t_id
 * @property string $xa_title
 * @property string $xa_abstract
 * @property string $xa_title_picture
 * @property string $xa_content
 * @property string $xa_author
 * @property string $xa_type
 * @property string $xa_keywords
 * @property string $xa_description
 * @property string $xa_souch
 * @property string $xa_auditing
 * @property string $xa_state
 * @property string $xa_status
 * @property string $xa_operation
 * @property string $xa_headlines
 * @property string $xa_top
 * @property string $xa_recommend
 * @property string $xa_c_id
 * @property string $xa_browse
 * @property string $xa_thumbs
 * @property string $xa_enclosure_id
 * @property string $xa_create_time
 * @property string $xa_update_time
 * @property string $xa_remark
 */
class Article extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'xa_article';
    }

    public function behaviors() {
        return [
            [
                'class'=>TimestampBehavior::className(),
                'attributes'=>[
                    //创建时间
                     ActiveRecord::EVENT_BEFORE_INSERT=>['xa_create_time','xa_update_time'],
                    //修改时间
                     ActiveRecord::EVENT_BEFORE_UPDATE=>['xa_update_time']

                ],
                //设置默认值
                 'value'=>date('Y-m-d H:i:s')

            ]

        ];
    }


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['xa_content'], 'string'],
            [['xa_t_id', 'xa_title', 'xa_abstract', 'xa_title_picture', 'xa_author', 'xa_type', 'xa_keywords', 'xa_description', 'xa_souch', 'xa_auditing', 'xa_state', 'xa_status', 'xa_operation', 'xa_headlines', 'xa_top', 'xa_recommend', 'xa_c_id', 'xa_browse', 'xa_thumbs', 'xa_enclosure_id', 'xa_create_time', 'xa_update_time', 'xa_remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'xa_t_id' => '文章分类',
            'xa_title' => '文章标题',
            'xa_abstract' => '文章简介',
            'xa_title_picture' => '文章标题图片',
            'xa_content' => '文章内容',
            'xa_author' => '文章作者',
            'xa_type' => '作者状态',
            'xa_keywords' => '文章关键字',
            'xa_description' => '文章描述',
            'xa_souch' => '文章来源',
            'xa_auditing' => '文章审核人',
            'xa_state' => '审核状态',
            'xa_status' => '发布状态',
            'xa_operation' => '操作类型',
            'xa_headlines' => '是否头条',
            'xa_top' => '是否置顶',
            'xa_recommend' => '是否推荐',
            'xa_c_id' => '评论数量',
            'xa_browse' => '浏览数量',
            'xa_thumbs' => '点赞数量',
            'xa_enclosure_id' => '附件',
            'xa_create_time' => '创建时间',
            'xa_update_time' => '更新时间',
            'xa_remark' => '备注',
        ];
    }


    /**
     *获取文章分类名称
     */
    public function fication($xa_t_id)
    {
        return $xa_t_id!=null?Type::findOne(['id'=>$xa_t_id])->xa_name:null;

    }








}
